import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    userInfo: null,
    token: localStorage.getItem('token') || '',
    isAuthenticated: !!localStorage.getItem('token')
  }),
  
  actions: {
    setUserInfo(info) {
      this.userInfo = info
    },
    
    setToken(token) {
      this.token = token
      this.isAuthenticated = true
      localStorage.setItem('token', token)
    },
    
    logout() {
      this.userInfo = null
      this.token = ''
      this.isAuthenticated = false
      localStorage.removeItem('token')
    }
  }
}) 